package com.aiyige.model.moment.entity;

import android.text.TextUtils;

import com.aiyige.base.api.JsonUtil;
import com.aiyige.base.gson.JsonTextAdapter;
import com.aiyige.model.PlayProgressModel;
import com.aiyige.model.moment.backup.CommodityBackup;
import com.aiyige.model.moment.backup.CreatorBackup;
import com.aiyige.model.moment.backup.DetailBackup;
import com.aiyige.model.moment.backup.InventoryBackup;
import com.aiyige.model.moment.backup.MediaSummary;
import com.aiyige.model.moment.backup.MineBackup;
import com.aiyige.model.moment.backup.MomentOnsaleBackup;
import com.aiyige.model.moment.backup.StatisticsBackup;
import com.aiyige.model.moment.backup.TagBackup;
import com.aiyige.utils.ListUtil;
import com.aiyige.utils.MomentUtil;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.google.gson.annotations.JsonAdapter;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 功能: Moment父类. <br/>
 *
 * @author wangzhijun
 * @date 2018-01-16 10:07
 * @since JDK 1.8
 */
public class Moment implements MultiItemEntity, Serializable {
    public static final String MOMENT_LIST_TYPE_ATTENTION = "attention";
    public static final String MOMENT_LIST_TYPE_LASTEST = "lastest";
    public static final String MOMENT_LIST_TYPE_HEATEST = "heatest";
    public static final String MOMENT_LIST_TYPE_RECOMMEND = "recommend";
    public static final String SUBJECT_PHOTO = "photo";
    public static final String SUBJECT_VIDEO = "video";
    public static final String SUBJECT_ARTICLE = "article";
    public static final String SUBJECT_SPECIAL_TOPIC = "special_topic";
    public static final String SUBJECT_VIDEO_COURSE = "video_course";
    public static final String SUBJECT_MAJOR_COURSE = "major_course";
    public static final String SUBJECT_TRAINING_COURSE = "training_course";
    public static final String SUBJECT_PRIVATE_COURSE = "private_course";
    public static final String SUBJECT_TRAINING_CARD = "training_card";
    public static final int SUBJECT_PHOTO_INDEX = 1;
    public static final int SUBJECT_VIDEO_INDEX = 2;
    public static final int SUBJECT_ARTICLE_INDEX = 3;
    public static final int SUBJECT_SPECIAL_TOPIC_INDEX = 4;
    public static final int SUBJECT_VIDEO_COURSE_INDEX = 5;
    public static final int SUBJECT_MAJOR_COURSE_INDEX = 6;
    public static final int SUBJECT_TRAINING_COURSE_INDEX = 7;
    public static final int SUBJECT_PRIVATE_COURSE_INDEX = 8;
    public static final int SUBJECT_TRAINING_CARD_INDEX = 9;
    public static final int SUBJECT_UNKNOWN_INDEX = 0;
    public static final int STATUS_IN_REVIEW = 0;
    public static final int STATUS_REVIEW_PASSED = 1;
    public static final int STATUS_REJECT = 2;
    public static final int STATUS_PUT_ON = 3;
    public static final int STATUS_GET_OFF = 4;
    public static final int STATUS_SAVE = 5;
    public static final int STATUS_TRANSCODING = 6;
    public static final int COURSE_TAKE_EFFECT_CONDITION_OPEN_DATE = 1;
    public static final int COURSE_TAKE_EFFECT_CONDITION_POPULATION = 2;
    public static final String TRAINING_CARD_TAKE_EFFECT_TYPE_IMMEDIATE = "immediate";
    public static final String TRAINING_CARD_TAKE_EFFECT_TYPE_ATTENDANCE = "attendance";
    public static final String TRAINING_CARD_TYPE_RECHARGEABLE_CARD = "rechargeable_card";
    public static final String TRAINING_CARD_TYPE_MEASURED_CARD = "measured_card";
    public static final String TRAINING_CARD_TYPE_TIME_CARD = "time_card";
    public static final String TRAINING_CARD_VALIDITY_UNIT_YEAR = "year";
    public static final String TRAINING_CARD_VALIDITY_UNIT_MONTH = "month";
    public static final String TRAINING_CARD_VALIDITY_UNIT_DAY = "day";
    public static final String MOMENT_AIYIGE_APPLICATION_PC = "pc";
    public static final String MOMENT_AIYIGE_APPLICATION_SOURCE_IOS = "ios";
    public static final String MOMENT_AIYIGE_APPLICATION_ANDROID = "android";
    private String id;

    /**
     * 渠道
     */
    private String channel;
    /**
     * 媒体信息
     */
    private MediaSummary mediaSummary;
    /**
     * 主题
     */
    private String subject;
    /**
     * 封面URL
     */
    private List<String> cover;
    /**
     * 标题
     */
    private String title;
    /**
     * 简介
     */
    private String summary;
    /**
     * 发布人ID
     */
    private String creator;
    /**
     * 城市ID
     */
    private String cityId;
    /**
     * 状态：0-待审核，1-审核通过，2-审核不通过，3-上架，4-下架，5-暂存
     */
    private Integer status;
    /**
     * 分类ID
     */
    private String categoryId;
    /**
     * 后台处理时间（接收到的时间），毫秒
     */
    private Long processTime;

    /**
     * 保存时间(前端点击按钮时间，必须是当前时间之前3天)，毫秒
     */
    private Long createTime;

    /**
     * 更新时间，毫秒
     */
    private Long updateTime;
    /**
     * 发布时间
     */
    private Long onsellTime;

    /**
     * 跳转路由
     */
    private String router;

    /**
     * 标签Name的json列表
     */
    private List<TagBackup> tags;

    /**
     * JSON价格信息
     */
    private CommodityBackup commodityBackup;

    /**
     * JSON统计数据，如点赞、收藏、评论、浏览、购买人数等信息
     */
    private StatisticsBackup statisticsBackup;

    /**
     * JSON发布人信息
     */
    private CreatorBackup creatorBackup;

    /**
     * 我的状态
     */
    private MineBackup mineBackup;

    /**
     * 库存信息
     */
    private InventoryBackup inventoryBackup;

    /**
     * JSON图文说明（文章、图片和视频）和保障（按照列表查询时此项为空）
     */
    private DetailBackup detailBackup;

    /**
     * 子类信息
     */
    @JsonAdapter(JsonTextAdapter.class)
    private String moreBackup;

    /**
     * 原中舞网系统的ID
     */
    private Long orginId;

    /**
     * TA的相关
     */
    private List<Moment> recommendMineBackup;
    /**
     * 动态的备注信息，可能为驳回信息
     */
    private String remark;


    /**
     * 更多推荐
     */
    private List<Moment> recommendOtherBackup;
    /**
     * 视频数量
     */

    private int subjectIndex;

    /**
     * 审核时间，毫秒
     */
    private Long auditTime;

    /**
     * 热度
     */
    private Long heat = 0L;

    /**
     * MD5
     */
    private String md5Sign;

    /**
     * 是否开放购买
     */
    private Boolean letBuy;

    /**
     * 版本，如果卖家修改了则版本号会变。支付的时候会根据这个来判断是否有价格变动
     */
    private int version;

    /**
     * 发布来源
     */
    private String aiyigeApplication;


    private boolean consumptionGuarantee;

    private MomentOnsaleBackup onSalesBackup;

    public MomentOnsaleBackup getOnSalesBackup() {
        return onSalesBackup;
    }

    public void setOnSalesBackup(MomentOnsaleBackup onSalesBackup) {
        this.onSalesBackup = onSalesBackup;
    }

    public String getAiyigeApplication() {
        return aiyigeApplication;
    }

    public void setAiyigeApplication(String aiyigeApplication) {
        this.aiyigeApplication = aiyigeApplication;
    }

    public int getVersion() {
        return version;
    }

    public void setVersion(int version) {
        this.version = version;
    }

    List<PlayProgressModel> studyProgressBackup;//上次播放进度

    public String getWebUrl() {
        return webUrl == null ? "" : webUrl;
    }

    public void setWebUrl(String webUrl) {
        this.webUrl = webUrl;
    }

    String webUrl;

    public List<PlayProgressModel> getStudyProgressBackup() {
        return studyProgressBackup;
    }

    public void setStudyProgressBackup(List<PlayProgressModel> studyProgressBackup) {
        this.studyProgressBackup = studyProgressBackup;
    }

    public Long getOnsellTime() {
        return onsellTime;
    }

    public void setOnsellTime(Long onsellTime) {
        this.onsellTime = onsellTime;
    }

    public Long getAuditTime() {
        return auditTime;
    }

    public void setAuditTime(Long auditTime) {
        this.auditTime = auditTime;
    }

    public Long getHeat() {
        return heat;
    }

    public void setHeat(Long heat) {
        this.heat = heat;
    }

    public String getMd5Sign() {
        return md5Sign;
    }

    public void setMd5Sign(String md5Sign) {
        this.md5Sign = md5Sign;
    }

    public MediaSummary getMediaSummary() {
        return mediaSummary;
    }

    public void setMediaSummary(MediaSummary mediaSummary) {
        this.mediaSummary = mediaSummary;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getChannel() {
        return channel;
    }

    public void setChannel(String channel) {
        this.channel = channel;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public List<String> getCover() {
        return cover;
    }

    public void setCover(List<String> cover) {
        this.cover = cover;
    }

    public String getTitle() {
        return title == null ? "" : title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getSummary() {
        return summary == null ? "" : summary;
    }

    public void setSummary(String summary) {
        this.summary = summary;
    }

    public String getCreator() {
        return creator;
    }

    public void setCreator(String creator) {
        this.creator = creator;
    }

    public String getCityId() {
        return cityId;
    }

    public void setCityId(String cityId) {
        this.cityId = cityId;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(String categoryId) {
        this.categoryId = categoryId;
    }

    public Long getProcessTime() {
        return processTime;
    }

    public void setProcessTime(Long processTime) {
        this.processTime = processTime;
    }

    public Long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Long createTime) {
        this.createTime = createTime;
    }

    public Long getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Long updateTime) {
        this.updateTime = updateTime;
    }

    public String getRouter() {
        return router;
    }

    public void setRouter(String router) {
        this.router = router;
    }

    public List<TagBackup> getTags() {
        return tags;
    }

    public void setTags(List<TagBackup> tags) {
        this.tags = tags;
    }

    public CommodityBackup getCommodityBackup() {
        return commodityBackup;
    }

    public void setCommodityBackup(CommodityBackup commodityBackup) {
        this.commodityBackup = commodityBackup;
    }

    public StatisticsBackup getStatisticsBackup() {
        return statisticsBackup;
    }

    public void setStatisticsBackup(StatisticsBackup statisticsBackup) {
        this.statisticsBackup = statisticsBackup;
    }

    public CreatorBackup getCreatorBackup() {
        return creatorBackup;
    }

    public void setCreatorBackup(CreatorBackup creatorBackup) {
        this.creatorBackup = creatorBackup;
    }

    public MineBackup getMineBackup() {
        return mineBackup;
    }

    public void setMineBackup(MineBackup mineBackup) {
        this.mineBackup = mineBackup;
    }

    public InventoryBackup getInventoryBackup() {
        return inventoryBackup;
    }

    public void setInventoryBackup(InventoryBackup inventoryBackup) {
        this.inventoryBackup = inventoryBackup;
    }

    public DetailBackup getDetailBackup() {
        return detailBackup;
    }

    public void setDetailBackup(DetailBackup detailBackup) {
        this.detailBackup = detailBackup;
    }

    public String getMoreBackup() {
        return moreBackup;
    }

    public void setMoreBackup(String moreBackup) {
        this.moreBackup = moreBackup;
    }

    public Long getOrginId() {
        return orginId;
    }

    public void setOrginId(Long orginId) {
        this.orginId = orginId;
    }

    public List<Moment> getRecommendMineBackup() {
        if (!ListUtil.isEmpty(recommendMineBackup) && recommendMineBackup.size() > 4) {
            recommendMineBackup = recommendMineBackup.subList(0, 4);
        }
        return recommendMineBackup;
    }

    public void setRecommendMineBackup(List<Moment> recommendMineBackup) {
        this.recommendMineBackup = recommendMineBackup;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public List<Moment> getRecommendOtherBackup() {
        if (!ListUtil.isEmpty(recommendOtherBackup) && recommendOtherBackup.size() > 4) {
            recommendOtherBackup = recommendOtherBackup.subList(0, 4);
        }
        return recommendOtherBackup;
    }

    public void setRecommendOtherBackup(List<Moment> recommendOtherBackup) {
        this.recommendOtherBackup = recommendOtherBackup;
    }


    public int getSubjectIndex() {
        return subjectIndex;
    }

    public void setSubjectIndex(int subjectIndex) {
        this.subjectIndex = subjectIndex;
    }

    public Boolean getLetBuy() {
        return letBuy;
    }

    public void setLetBuy(Boolean letBuy) {
        this.letBuy = letBuy;
    }

    @Override
    public int getItemType() {
        return 0;
    }


    public Moment() {
    }

    /**
     * 服务器返回的Moment不要直接用不然会有null成员
     *
     * @param other
     * @return
     */

    public Moment(Moment other) {
        setAiyigeApplication(TextUtils.isEmpty(other.getAiyigeApplication()) ? "" : other.getAiyigeApplication());
        setLetBuy(other.getLetBuy() == null ? false : other.getLetBuy());
        setOnsellTime(other.getOnsellTime() == null ? 0l : other.getOnsellTime());
        setAuditTime(other.getAuditTime() == null ? 0l : other.getAuditTime());
        setHeat(other.getHeat() == null ? 0l : other.getHeat());
        setMd5Sign(TextUtils.isEmpty(other.getMd5Sign()) ? "" : other.getMd5Sign());
        setRemark(TextUtils.isEmpty(other.getRemark()) ? "" : other.getRemark());
        setId(TextUtils.isEmpty(other.getId()) ? "" : other.getId());
        setChannel(TextUtils.isEmpty(other.getChannel()) ? "" : other.getChannel());
        setSubject(TextUtils.isEmpty(other.getSubject()) ? "" : other.getSubject());
        setCover(ListUtil.isEmpty(other.getCover()) ? new ArrayList<String>() : other.getCover());
        setTitle(TextUtils.isEmpty(other.getTitle()) ? "" : other.getTitle());
        setSummary(TextUtils.isEmpty(other.getSummary()) ? "" : other.getSummary());
        setCreator(TextUtils.isEmpty(other.getCreator()) ? "" : other.getCreator());
        setCityId(TextUtils.isEmpty(other.getCityId()) ? "" : other.getCityId());
        setStatus(other.getStatus() == null ? 0 : other.getStatus());
        setCategoryId(TextUtils.isEmpty(other.getCategoryId()) ? "" : other.getCategoryId());
        setProcessTime(other.getProcessTime() == null ? 0l : other.getProcessTime());
        setCreateTime(other.getCreateTime() == null ? 0l : other.getCreateTime());
        setUpdateTime(other.getUpdateTime() == null ? 0l : other.getUpdateTime());
        setRouter(TextUtils.isEmpty(other.getRouter()) ? "" : other.getRouter());
        setTags(ListUtil.isEmpty(other.getTags()) ? new ArrayList<TagBackup>() : other.getTags());
        setMoreBackup(other.getMoreBackup());
        setMediaSummary(new MediaSummary(other.getMediaSummary()));
        setCommodityBackup(new CommodityBackup(other.getCommodityBackup()));
        setStatisticsBackup(new StatisticsBackup(other.getStatisticsBackup()));
        setCreatorBackup(new CreatorBackup(other.getCreatorBackup()));
        setMineBackup(new MineBackup(other.getMineBackup()));
        setInventoryBackup(new InventoryBackup(other.getInventoryBackup()));
        setDetailBackup(new DetailBackup(other.getDetailBackup()));
        setOrginId(other.getOrginId() == null ? 0l : other.getOrginId());
        setRecommendMineBackup(ListUtil.isEmpty(other.getRecommendMineBackup()) ? new ArrayList<Moment>() : other.getRecommendMineBackup());
        setRecommendOtherBackup(ListUtil.isEmpty(other.getRecommendOtherBackup()) ? new ArrayList<Moment>() : other.getRecommendOtherBackup());
        setSubjectIndex(MomentUtil.convertSubjectToSubjectIndex(other.getSubject()));
        setStudyProgressBackup(other.getStudyProgressBackup());
        setWebUrl(other.getWebUrl());
        setVersion(other.getVersion());
        setOnSalesBackup(new MomentOnsaleBackup(other.getOnSalesBackup()));
    }

    public boolean isConsumptionGuarantee() {
        if (!TextUtils.isEmpty(getMoreBackup())) {
            MoreBackup moreBackup = JsonUtil.toObject(getMoreBackup(), MoreBackup.class);
            if (moreBackup != null) {
                return moreBackup.isConsumptionGuarantee();
            }
        }
        return consumptionGuarantee;
    }


}

